<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>线路信息展示</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <!--<link rel="stylesheet" href="../../layui/css/layui.css" media="all">-->
    <script type="text/javascript" src="../../js/jquery-3.4.1.js"></script>
</head>
<body>
<div style="padding: 20px;">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body">


                    <form class="layui-form" action="" style="margin-top: 30px;margin-left: 50px">
                        <div class="layui-inline">
                            <label class="layui-form-label">线路编号：</label>
                            <div class="layui-input-inline">
                                <div class="layui-input-inline">
                                    <input type="tel" name="line_number" lay-verify="required|line_number" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">线路状态：</label>
                            <div class="layui-input-inline">
                                <select name="state_name2" lay-verify="required" lay-search="">
                                    <option value="3">正常</option>
                                    <option value="4">检修中</option>
                                </select>
                            </div>
                        </div>


                        <div class="layui-inline">
                            <div>
                                <button type="button" id="search" class="layui-btn" lay-submit="search" lay-filter="search" style="margin-left: 30px">查询</button>
                            </div>
                        </div>

                        <div class="layui-inline">
                            <button type="button" id="add_line" lay-event="add_line" class="layui-btn" style="margin-left: 30px">
                                <i class="layui-icon"></i>添加线路</button>
                        </div>
                    </form>

                </div>
            </div>
        </div>
    </div>

    <div style="margin-left: 30px;width:1250px;height:200px;background-color: white">
        <table class="layui-hide" id="tower_table" lay-filter="tower_table" ></table>
    </div>
</div>
</div>



<!--<script src="../layui/layui.js" charset="utf-8"></script>-->
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>
        <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>
        <button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>
    </div>
</script>
<script type="text/html" id="barDemo" >
    <a class="layui-btn layui-btn-xs" lay-event="stop">更改状态</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    <a class="layui-btn layui-btn-xs" id="edit" lay-event="edit">修改</a>
</script>

<script>
    //添加按钮点击事件
    $(document).on('click',"#add_line",function () {
        var index = layer.open({
            type: 2,
            title: ['线路信息添加', 'font-size:13px;background-color: #23262E;color:white;text-algin:center'],
            shade: [0.7, '#393D49'],
            area: ['62%', '62%'],
            closeBtn: 2,
            id:'weiyibiaoshi',
            shadeClose:true,
            content: 'pages/line/add_Line.html',
        });
    })
</script>

<script>

    layui.use(['table','form', 'layedit', 'laydate'], function(){
        var table = layui.table
            ,form = layui.form
            ,layer = layui.layer;
        form.render("select");
        table.render({
            elem: '#tower_table'
            ,url:'/queryListLine.do'
            ,toolbar: '#toolbarDemo'
            ,title: '线路信息表'
            ,totalRow: true
            ,cols: [[
                {type: 'checkbox', fixed: 'left'}
                ,{field:'line_id', title:'ID',width:100}
                ,{field:'line_number', title:'线路编号',width:120}
                ,{field:'line_name', title:'线路名称',width:100}
                ,{field:'start_tower', title:'起始杆号',width:100}
                ,{field:'stop_tower', title:'终止杆号',width:100}
                ,{field:'tower_number', title:'塔基数',width:100}
                ,{field:'state_name2', title:'运行状态',width:100}
                ,{field:'state_name', title:'启用状态',width:100}
                ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:200}
            ]]
            ,page:{
                limits:[5,10,15,20]
            }
        });

//        //查询
        $("#search").click(function () {
            var line_number = $("input[name=line_number]").val();
            var line_run = $("select[name=state_name2]").val();
//            alert(line_number +"    "+ line_run)
            table.reload('tower_table', {
                url: '/searchLine.do',
                method: "get",
                where: {line_number: line_number, line_run: line_run}//设定异步数据接口的额定参数
            });
        });




        //头工具栏事件
        table.on('toolbar(tower_table)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'getCheckData':
                    var data = checkStatus.data;
                    layer.alert(JSON.stringify(data));
                    break;
                case 'getCheckLength':
                    var data = checkStatus.data;
                    layer.msg('选中了：'+ data.length + ' 个');
                    break;
                case 'isAll':
                    layer.msg(checkStatus.isAll ? '全选': '未全选');
                    break;

                //自定义头工具栏右侧图标 - 提示
                case 'LAYTABLE_TIPS':
                    layer.alert('这是工具栏右侧自定义的一个图标按钮');
                    break;
            };
        });



        //监听行工具事件
        table.on('tool(tower_table)', function(obj){
            var data = obj.data;
            var line_id = data.line_id;
            if(obj.event === 'del'){
                layer.confirm('真的删除行么', function(index){
                    $.ajax({
                        url:"/deleteLine.do",
                        type:"post",
                        data:{line_id:line_id},
                        dataType:"json",
                        success:function (result) {
                            if (result.code == 200){
                                obj.del();
                                //执行重载
                                table.reload('tower_table',{
                                    where:{
                                        key:{
                                            time:new Date()
                                        }
                                    }
                                },'data');
                                layer.close(index);
                                alert(result.message)
                            }
                            //出现异常或者其他问题
                            if(result.code == 500){
                                alert(result.message);
                                layer.close(index);
                            }else if (result.code == 405){
                                layer.msg(result.msg,{icon:5});
                            }
                        }
                    });
                });
            } else if(obj.event === 'edit'){
                var index = layer.open({
                    type: 2,
                    title: ['线路信息编辑', 'font-size:13px;background-color: #23262E;color:white;text-algin:center'],
                    shade: [0.7, '#393D49'],
                    area: ['62%', '62%'],
                    closeBtn: 2,
                    shadeClose:-true,
                    content: 'pages/line/edit_Line.html',
                    success:function (layero,index) {
                        var body = layer.getChildFrame('body', index);
                        var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                        //数据回显
                        body.find('input[name=line_id]').val(data.line_id);
                        body.find('input[name=line_number]').val(data.line_number);
                        body.find('input[name=line_name]').val(data.line_name);
                        body.find('input[name=start_tower]').val(data.start_tower);
                        body.find('input[name=stop_tower]').val(data.stop_tower);
                        body.find('input[name=tower_number]').val(data.tower_number);
                        body.find('input[name=state_name2]').val(data.state_name2);
                        body.find('input[name=state_name]').val(data.state_name);
                        body.find('input[name=line_length]').val(data.line_length);
                        body.find('input[name=line_backlength]').val(data.line_backlength);
                        body.find('input[name=line_rank]').val(data.line_rank);
                        body.find('input[name=line_date]').val(data.line_date);
                        body.find('input[name=line_notes]').val(data.line_notes);
                    },end:function () {
                        table.reload('tower_table',{
                            where:{
                                key:{
                                    time:new Date()
                                }
                            }
                        },'data');
                    }
                });
            }else if(obj.event === 'stop'){
                var state_name = data.state_name;
                var line_id = data.line_id;
                $.ajax({
                    url:"/modifiesLineStatus.do",
                    type:"post",
                    data:{state_name:state_name,line_id:line_id},
                    dataType:"json",
                    success:function (result) {
                        if(result.code == 200){
                            alert(result.message);
                            table.reload('tower_table',{//数据表格重载
                                where:{
                                    key:{
                                        time:new Date()
                                    }
                                }
                            },'data');
                        }else if (result.code == 405){
                            layer.msg(result.msg,{icon:5});
                        }
                    }
                });
            }
        });
    });


</script>





</body>
</html>